package com.fake

import android.view.View
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.RecyclerView
import com.helloandroid.BaseZhuanFragment
import com.helloandroid.R
import com.helloandroid.models.ZhuanViewModel
import com.helloandroid.vo.Type

class FakeZhuanFragment: BaseZhuanFragment() {

    private lateinit var adapter: FakeTaskAdapter
    val model: ZhuanViewModel by viewModels()
    override fun initUI() {
        adapter.notifyDataSetChanged()
    }

    override fun switchToZouFragment() {
        val mainActivity = requireActivity() as FakeMainActivity
        mainActivity.swithToZouFragment()
    }

    override fun swithToWodeFragment() {
        val mainActivity = requireActivity() as FakeMainActivity
        mainActivity.swithToWodeFragment()
    }

    override fun getLayoutResId(): Int  = R.layout.fragment_fake_zhuan

    override fun initView(view: View) {

        localDataLst.clear()
        dataLst.forEach {
            when(it.type){
                Type.Shoucitixian,
                Type.ViewVideo,
                Type.ZhuanPan,
                Type.ChengYu,
                Type.JiFuZi,
                Type.HongBaoYu ->{
                    // 不添加
                }

                else-> localDataLst.add(it)
            }
        }

        // init listview
        val rvTask = findViewById<RecyclerView>(R.id.rvTask)
        adapter = FakeTaskAdapter(this)
        rvTask.adapter = adapter
    }

    override fun initData() {
        model.getInfo { success, info ->
            isReady = success
            if (isReady) {
                mInfo = info
                initUI()
            }
        }
    }
}